home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / DIKUMUD.ZIP / PCEDIT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-28  |  10.4 KB  |  442 lines

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <ctype.h>
  4. #include <malloc.h>
  5. #include <time.h>
  6. #include "wizlist.h"
  7. #include "structs.h"
  8. #include "utils.h"
  9. #include "db.h"
  10. #include "comm.h"
  11. #include "handler.h"
  12. #include "limits.h"
  13. #include "race.h"
  14. #include "opinion.h"
  15. #include "hash.h"
  16.  
  17. struct my_char_data {
  18.   struct char_file_u grunt;
  19.   short AXE;
  20. }**dummy;
  21.  
  22. void muck(int orig_ammt, char name[80]);
  23. void specific_axe(int orig_ammt, char name[80]);
  24. void inactive_god_axe (int orig_ammt,time_t CURRENT_TIME);
  25. void inactive_axe(int orig_ammt, time_t CURRENT_TIME);
  26. void zero_bank();
  27. char *time_print(long et);
  28. int load_playerfile(char *argv[]);
  29. int orig_ammt=0, after_ammt=0;
  30. int our_pos = 0;
  31.  
  32.  
  33. int get_int(int min, int max, int zero_ok)
  34. {
  35.   char buff[20];   /* We should never need anything over 10^20th */
  36.   int i,isok=FALSE;
  37.   printf("\n");
  38.   do {
  39.     printf(">");
  40.     gets(buff);
  41.     i=atoi(buff);
  42.     if( i > max || i < min)
  43.       printf("Hey bozo, you can't do that.\n");
  44.     else if(i==0 && !zero_ok)
  45.       printf("Sorry peanut-head, that was unacceptable.\n");
  46.     else isok=TRUE;
  47.   }while(!isok);
  48.   return i;
  49. }
  50.  
  51. get_string(char *s)
  52. {
  53.   do {
  54.     printf(">");
  55.     gets(s);
  56.     if(*s=='\0') printf("There was nothing there!\n");
  57.     else if(*s==' ')  printf("Please do not start with a blank.\n");
  58.   }while(*s=='\0' || *s==' ');
  59. }
  60.  
  61. main(int argc, char *argv[])
  62. {
  63.   char tempbuf[255];
  64.   time_t CURRENT_TIME;
  65.   int choice,j;
  66.   register i;
  67.   int number_level[9];
  68.   
  69.   system("clear");
  70.   if(argc != 3) {
  71.     printf("please use this program in the following format:");
  72.     printf("\n<%s> <input file> <output file>\n",argv[0]);
  73.     exit(0);
  74.   }
  75.   if(!strcmp(argv[1],argv[2])) {
  76.     printf("\nPlease use a seperate files for input and output.\n");
  77.     exit(0);
  78.   }
  79.   orig_ammt=load_playerfile(argv);
  80.   CURRENT_TIME=time(0);
  81.   for(i=0;i<orig_ammt;i++) 
  82.     dummy[i]->AXE=FALSE;
  83.  
  84.   printf("\nStructures initialized.");
  85.   printf("\nCurrent time: %s\n",time_print(CURRENT_TIME));
  86.   do {
  87.     printf("\n    What to do?");
  88.     printf("\n0 -\t Exit");
  89.     printf("\n1 -\t Routine deletion of low level inactive characters.");
  90.     printf("\n2 -\t Routine demotion of inactive gods.");
  91.     printf("\n3 -\t Delete a specific player.");
  92.     printf("\n4 -\t Muck with a player in depth.");
  93.     printf("\n5 -\t Find those who have a certain item number.");
  94.     printf("\n6 -\t Zero all bank accounts.");
  95.     printf("\n\nChanges are updated upon entering 0");
  96.     printf("\nWell? > ");
  97.     gets(tempbuf);
  98.     choice=atoi(tempbuf);
  99.     switch(choice) {
  100.     case 1:
  101.       inactive_axe(orig_ammt,CURRENT_TIME);
  102.       break;
  103.     case 2:
  104.       inactive_god_axe(orig_ammt,CURRENT_TIME);
  105.       break;
  106.     case 3:
  107.       printf("\nWhom do you want to delete?\n");
  108.       get_string(tempbuf);
  109.       specific_axe(orig_ammt,tempbuf);
  110.       break;
  111.     case 4:
  112.       printf("\nWhom do you want to mess around with?\n");
  113.       get_string(tempbuf);
  114.       muck(orig_ammt,tempbuf);
  115.       break;
  116.     case 5:
  117.       printf("\nWhat item number?\n");
  118.       j=get_int(1,30000,FALSE);
  119.       access_rent_files(orig_ammt,j);
  120.       break;
  121.     case 6:
  122.       zero_bank();
  123.       break;
  124.     default:
  125.       after_ammt=spit_out_remains(argv,orig_ammt);
  126.       choice=0;
  127.       printf("Playerfile adjusted by %d players.\n",after_ammt-orig_ammt);
  128.       printf("\nbye!\n");
  129.       break;
  130.     }
  131.   }while(choice);
  132. }
  133.  
  134. void menu2() {
  135.   printf("\n\n\n\t You can anything below, and more :)");
  136.   printf("\n1\t- edit levels");
  137.   printf("\n2\t- change the room that someone starts in.");
  138.   printf("\n3\t- change race (ghost is 29 (no can cast)).");
  139.   printf("\n> ");
  140. }
  141.  
  142. void muck(int orig_ammt, char name[80]) {
  143.   void menu2();
  144.   register i;
  145.   int l, count, f;
  146.   char temp[10];
  147.   char buffer[255];
  148.  
  149.   name[0]=toupper(name[0]);
  150.   printf("Do you wish to search from the beginning? (Y/N) ");
  151.   gets(buffer);
  152.   if((buffer[0] == 'y') || (buffer[0] == 'Y'))
  153.     f = 0;
  154.   else
  155.     f = our_pos;
  156.  
  157.   for(i=f;i<orig_ammt;i++) {
  158.     if(!(strcmp(name,dummy[i]->grunt.name))) {
  159.       our_pos = i;
  160.       menu2();
  161.       gets(temp);
  162.       l=atoi(temp);
  163.       switch(l) {
  164.       case 1:
  165.         printf("%s:\n", dummy[i]->grunt.name);
  166.     printf("Levels: M:%d C:%d W:%d T:%d D:%d K:%d",
  167.            dummy[i]->grunt.level[0],
  168.            dummy[i]->grunt.level[1],dummy[i]->grunt.level[2],
  169.            dummy[i]->grunt.level[3],dummy[i]->grunt.level[4],
  170.            dummy[i]->grunt.level[5]);
  171.  
  172.         for(count = 0; count <= 5; count++) {
  173.            printf("Current Level %d: %d\n", count, dummy[i]->grunt.level[count]);
  174.            printf("New Level [%d]: ", dummy[i]->grunt.level[count]);
  175.            gets(buffer);
  176.            if(buffer[0] == '\0')
  177.              f = dummy[i]->grunt.level[count];
  178.            else
  179.              f = atoi(buffer);
  180.            dummy[i]->grunt.level[count] = f;
  181.     }
  182.  
  183.     printf("%s\'s levels: M:%d C:%d W:%d T:%d D:%d K:%d",
  184.            dummy[i]->grunt.name, dummy[i]->grunt.level[0],
  185.                dummy[i]->grunt.level[1],dummy[i]->grunt.level[2],
  186.                dummy[i]->grunt.level[3],dummy[i]->grunt.level[4],
  187.                dummy[i]->grunt.level[5]);
  188.     break;
  189.       case 2:
  190.     printf("\n%s currently starts in room %d.",dummy[i]->grunt.load_room);
  191.     printf("\nNew room?\n");
  192.     dummy[i]->grunt.load_room=get_int(0,40000,TRUE);
  193.     printf("\nStart room set to %d.",dummy[i]->grunt.load_room);
  194.     break;
  195.       case 3:
  196.     printf("\nCurrent race is %d. (go look it up in race.h)",
  197.            dummy[i]->grunt.race);
  198.     printf("\nNew race is?\n");
  199.     dummy[i]->grunt.race=get_int(0,49,TRUE);
  200.     printf("\nRace set to %d.",dummy[i]->grunt.race);
  201.     break;
  202.       default:
  203.     printf("\nAck, wrong choice! :P");
  204.     break;
  205.       }
  206.     }
  207.   }
  208. }
  209.     
  210.       
  211.  
  212. void specific_axe(int orig_ammt, char name[80]) {
  213.   register i;
  214.   int j=FALSE;
  215.  
  216.   name[0]=toupper(name[0]);
  217.   for(i=0;i<orig_ammt,!j;i++) {
  218.     if(!(strcmp(name,dummy[i]->grunt.name))) {
  219.       dummy[i]->AXE=TRUE;
  220.       printf("%s's head found, putting it on the block.\n",
  221.          dummy[i]->grunt.name);
  222.       j=TRUE;
  223.     }
  224.   }
  225.   if(!j)
  226.     printf("%s's head could not be found.",name);
  227. }
  228.  
  229. void inactive_god_axe(int orig_ammt, time_t CURRENT_TIME) {
  230.   register i,j,max;
  231.   int amt=0;
  232.   i=j=max=0;
  233.  
  234.   for(i=0;i<orig_ammt;i++) {
  235.     if((CURRENT_TIME - dummy[i]->grunt.last_logon) > (long) (86400 * 30)) {
  236.       for(j=0,max=0;j<6;j++) {
  237.         if (dummy[i]->grunt.level[j] > max) {
  238.           max = dummy[i]->grunt.level[j];
  239.         }
  240.       }
  241.       if(max > 51 && max < 59) {
  242.     printf("%s prepared for demotion.",dummy[i]->grunt.name);
  243.     printf("  Was %d, now is",max);
  244.     max--;
  245.     for(j=0;j<6;j++) dummy[i]->grunt.level[j]=max;
  246.     printf(" %d.\n",max);
  247.         amt++;
  248.       }
  249.     }
  250.   }
  251. }
  252.  
  253.  
  254. void inactive_axe(int orig_ammt, time_t CURRENT_TIME) {
  255.   register i,j,max;
  256.   int amt=0;
  257.   i=j=max=0;
  258.  
  259.   for(i=0;i<orig_ammt;i++) {
  260.     if((CURRENT_TIME - dummy[i]->grunt.last_logon) > (long) (86400 * 120)) {
  261.       for(j=0,max=0;j<6;j++) {
  262.     if (dummy[i]->grunt.level[j] > max) {
  263.       max = dummy[i]->grunt.level[j];
  264.     }
  265.       }
  266.       if(max <51) {
  267.     dummy[i]->AXE=TRUE;
  268.     amt++;
  269.       }
  270.     }
  271.   }
  272.   printf("\n%d players prepared for axing.",amt);
  273. }
  274.  
  275. int spit_out_remains(char *argv[], int ammt) {
  276.   FILE *fl;
  277.   int i,j;
  278.  
  279.   if(!(fl = fopen(argv[2], "w"))) {
  280.     printf("\nCan not open %s, bye!\n",argv[2]);
  281.     exit(0);
  282.   }
  283.   i=j=0;
  284.   for(;i<ammt;i++) {
  285.     if(!(dummy[i]->AXE)) {
  286.       fwrite(&(dummy[i]->grunt), sizeof(struct char_file_u), 1, fl);
  287.       j++;
  288.     }
  289.   }
  290.   return j;
  291. }
  292.   
  293. int load_playerfile(char *argv[]) {
  294.   int ammt=0;
  295.   FILE *fl;
  296.  
  297.   if (!(fl = fopen(argv[1], "r")))        {
  298.     printf("\nCan not open %s, bye!\n",argv[1]);
  299.     exit(0);
  300.   }
  301.   dummy=(struct my_char_data **)malloc(4000 * sizeof(dummy));
  302.   access_rent_files();
  303.   if(dummy==NULL) {
  304.     printf("ack\n");
  305.   }
  306.   for (;!feof(fl);)    {
  307.     dummy[ammt]=(struct my_char_data *)malloc(sizeof(struct my_char_data));
  308.     fread(&(dummy[ammt]->grunt), sizeof(struct char_file_u), 1, fl);
  309.     /*     printf("\n[%s] <%d>",dummy[ammt]->grunt.name,ammt); */
  310.     if (!feof(fl)) {
  311.       ammt++;
  312.     }
  313.   }
  314.   printf("\n%d players read.\n",ammt);
  315.   return ammt;
  316. }
  317.   
  318.  
  319. char *time_print(long et)
  320. {
  321.   char *buff;
  322.  
  323.   buff= (char *)asctime(localtime(&et));
  324.   *(buff + strlen(buff) -1) = '\0';
  325.   return(buff);
  326. }
  327. /*
  328. int SearchForNameFromPos(char *arg, int pos)
  329. {
  330.  register int i;
  331.  
  332.  if(pos > orig_amnt)
  333.    return(-1);
  334.  
  335.  for(i = pos; i < orig_amnt; i++)
  336.    if(!strcasecmp(dummy[i]->grunt.name, arg))
  337.      return(i);
  338.  
  339.  return(-1);
  340. }
  341. */
  342.  
  343. void access_rent_files(int number, int ITEM, char buf[40]) {
  344. /*
  345.   int ReadObjs(FILE *fl, struct obj_file_u *st);
  346.  
  347.   char buff2[80];
  348.   FILE *fl;
  349.   int i,j,tried,succeed;
  350.   struct obj_file_u muck;
  351.  
  352.   for(i=0;i<number;i++) {
  353.     j=tried=succeed=0;
  354.     while(buf[j] != '\0' && j<30) {
  355.       buf[j]=tolower(buf[j]);
  356.       j++;
  357.     } 
  358.     buf[j]='\0';
  359.     if(buf[0]=='e')
  360.     printf("\nAtteming to open %s's rent file.",buf);
  361.          if(strlen(buff) > sprintf) {
  362.       (,"~/lib/rent/%s",buff); 
  363.       if((fl=fopen(buf,"r")) != NULL ) {
  364.     if(ReadObjs(fl,&muck)) {
  365.       succeed++;
  366.       printf("\nReading the %d objects in %s's rent file.",
  367.          muck.number,buff);
  368.       for(j=0;j<muck.number && j< 250;j++) {
  369.         if(muck.objects[j].item_number == (sh_int) ITEM) {
  370.           printf("\n%s has it!",buff);
  371.         } 
  372.       }
  373.     } 
  374.     
  375.     }
  376.   }
  377.   printf("\nAttempted to read %d files, read %d in actuality.",i,succeed);
  378. */
  379. }
  380.  
  381. int ReadObjs( FILE *fl, struct obj_file_u *st)
  382. {
  383.   int i;
  384.  
  385.   if (feof(fl)) {
  386.     fclose(fl);
  387.     return(FALSE);
  388.     printf("\nEmpty file.");
  389.   }
  390.     
  391.   fread(st->owner, sizeof(st->owner), 1, fl);
  392.   if (feof(fl)) {
  393.     fclose(fl);
  394.     printf("\nFailed to read file owner's name, [%s].",st->owner);
  395.     return(FALSE);
  396.   }
  397.   fread(&st->gold_left, sizeof(st->gold_left), 1, fl);
  398.   if (feof(fl)) {
  399.     fclose(fl);
  400.     printf("\nFailed to read gold_left.");
  401.     return(FALSE);
  402.   }
  403.   fread(&st->total_cost, sizeof(st->total_cost), 1, fl);
  404.   if (feof(fl)) {
  405.     fclose(fl);
  406.     printf("\nFailed to read total_cost.");
  407.     return(FALSE);
  408.   }
  409.   fread(&st->last_update, sizeof(st->last_update), 1, fl);
  410.   if (feof(fl)) {
  411.     fclose(fl);
  412.     printf("\nFailed to read last update time.");
  413.     return(FALSE);
  414.   }
  415.   fread(&st->minimum_stay, sizeof(st->minimum_stay), 1, fl);
  416.   if (feof(fl)) {
  417.     fclose(fl);
  418.     printf("\nFailed to read minimum stay.");
  419.     return(FALSE);
  420.   }
  421.   fread(&st->number, sizeof(st->number), 1, fl);
  422.   if (feof(fl)) {
  423.     fclose(fl);
  424.     printf("\nFailed to read the number of items stored.");
  425.     return(FALSE);
  426.   }
  427.   for (i=0;i<st->number;i++) {
  428.     fread(&st->objects[i], sizeof(struct obj_file_elem), 1, fl);
  429.   }
  430. }
  431.  
  432.  
  433. void zero_bank()
  434. {
  435.   register i;
  436.  
  437.   for(i=0;i<orig_ammt;i++) {
  438.     dummy[i]->grunt.points.bankgold = 0;
  439.   }
  440.   printf("All bank accounts set to 0.\n");
  441. }
  442.